<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
    /**
     * 显示首页
     */
    public function index() {
        $this->display();
    }
    
    /**
     * 显示系统信息
     * add by Jeff at 2014-02-22
     */
    public function sysInfo() {
        $loginTime = M('sysuser')->getFieldById(session('uid'), 'logintime');
        $this->php_version = 'PHP版本：' . PHP_VERSION;
        $this->db_version = '数据库版本：' . mysql_get_server_info();
        $this->title = '欢迎回来，亲爱的' . session('username') . '，您上次登录的时间是：' .  session('logintime');
        $this->display();
    }
	
	/**
	 * 修改用户
	 */
	 public function edit(){
	 	if(IS_POST){
	 		$sysuser = $this->sysuser;
			$sysuser['password'] = md5(I('password'));
			$sysuser['name'] = I('name');
			$this->ajaxReturn(M('sysuser')->save($sysuser));
	 	}else{
	 		if(session('sysuid')){
	 			$this->display();
	 		}else{
	 			$this->redirect('/Admin/Login/index');
	 		}
	 	}
	 }
	 /**
	  * 检查旧密码是否正确
	  */
	  public function checkpsw(){
	  	$sysuser = $this->sysuser;
		$oldpsw = md5(I('oldpsw'));
		if($oldpsw == $sysuser['password']){
			$this->ajaxReturn(1);
		}
	  }
	public function logout(){
		session('uid',null);
		$this->redirect('Login/index');
	}
}